package com.example.xiongmao.controller;

import com.example.xiongmao.entity.DTO.CommonStatus;
import com.example.xiongmao.entity.DTO.admin.addAdminDTO;
import com.example.xiongmao.entity.DTO.admin.adminChargeDTO;
import com.example.xiongmao.entity.PageResult;
import com.example.xiongmao.entity.Result;
import com.example.xiongmao.entity.VO.admin.adminChargeVO;
import com.example.xiongmao.service.adminChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class adminChargeController {
    @Autowired
    private adminChargeService adminchargeService;
    // 分页条件查询
    @GetMapping
    public Result<PageResult> list(adminChargeDTO adminchargeDTO){
        PageResult pageResult = adminchargeService.list(adminchargeDTO);
        System.out.println("page:"+adminchargeDTO.getPage()+"pageSize"+adminchargeDTO.getPageSize());
        return Result.success(pageResult);
    }

    // 新增用户
    @PostMapping
    public Result addAdmin(@RequestBody addAdminDTO addAdmin){
        adminchargeService.add(addAdmin);
        return Result.success();
    }

    // 编辑回显
    @GetMapping("/{id}")
    public Result getByUserId(@PathVariable Integer id){
        adminChargeVO admins = adminchargeService.getbyId(id);
        return Result.success(admins);
    }

    // 编辑用户信息
    @PutMapping
    public Result updateAdmin(@RequestBody addAdminDTO addAdmin){
        System.out.println("前端传回来的："+addAdmin);
        adminchargeService.updateAdmin(addAdmin);
        return Result.success();
    }

    // （批量）删除用户信息
    @DeleteMapping
    public Result deleteAdmin(@RequestParam List<Integer> ids){
        System.out.println("当前要删除的ids:"+ids);
        adminchargeService.deleteBatch(ids);
        return Result.success();
    }

    // 禁用用户状态
    @PutMapping("/status")
    public Result AdminStatusChange(@RequestBody CommonStatus adminStatus){
        System.out.println("当前要修改状态的ids:"+adminStatus);
        adminchargeService.adminStatusChange(adminStatus);
        return Result.success();
    }
}
